package ui;

import java.util.Date;

import model.File;
import model.Server;
import ListManager.FileListManager;
import ListManager.ServerListManager;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.ui.R;

public class SummaryActivity extends Activity{
	private TextView fileListText;
	private TextView totalFileText;
	private ListView fileListView;
	private Button nextButton;
	private Button backButton;
	
	public static SummaryActivity activity;
	private Server server;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.server_file_layout);
		activity = this;
		
		//Info about server
		Intent intent = getIntent();
		int pos = intent.getIntExtra("position", 0);
		server = ServerListManager.getInstance().getServerList().get(pos);
		
		//View Element
		fileListText = (TextView)findViewById(R.id.fileListText);
		fileListView = (ListView)findViewById(R.id.fileListView);
		nextButton = (Button) findViewById(R.id.nextButton);
		backButton = (Button) findViewById(R.id.backButton);
		totalFileText = (TextView)findViewById(R.id.totalFileText);
		
		//View Initialisation
		nextButton.setEnabled(false);
		fileListText.setText(server.getName()+" "+getResources().getString(R.string.fileList));
		totalFileText.setText(getResources().getString(R.string.totalFile)+" 0");
		
		//textview font setting
		Typeface font = Typeface.createFromAsset(getAssets(), "font/champ.ttf");
		fileListText.setTypeface(font);
		totalFileText.setTypeface(font);
		
		
		//TODO
		for(int i =1;i<20;i++){
			File f = new File();
			f.setName("FileName"+i);
			f.setExtension("PNG");  
			f.setSize(100);
			f.setLastModified(new Date());
			f.setPath("C://document/repertoire");
			FileListManager.getInstance().addItem(0, f);
		}
		
		
		nextButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent myIntent = new Intent(FileListActivity.activity, DestinationServerActivity.class);
				Intent intent = getIntent();
				myIntent.putExtra("serverPosition", intent.getIntExtra("position", 0));
				startActivity(myIntent);      
                finish();
			}
		});
		
		backButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent myIntent = new Intent(FileListActivity.activity, MainActivity.class);
				startActivity(myIntent);      
                finish();
			}
		});
	}
	
    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflator=new MenuInflater(this);
		inflator.inflate(R.layout.pref_menu, menu);
		return super.onCreateOptionsMenu(menu);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case R.id.MENU_PREF:
		}
		return super.onOptionsItemSelected(item);
	}
	
	@Override
    public void onResume() {
        super.onResume();        
    }
	
	@Override
    public void onPause() {
        super.onPause();
    }
    
	@Override
	protected void onDestroy() {
		super.onDestroy();	
	}
}
